<?php
namespace App\Http\Controllers\Api;
use App\Helpers\Api\ApiResponse;
use App\Http\Controllers\Api\ApiController;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\DB;

/**
 * 移动运营商
 *
 */
class MoveController extends ApiController{
    /**
     * 移动
     * 请求接口测试
     *
     */
    public function index(){
        dump('kang');die;
        $sysparams = $this->getSystemParams('UIP_ENCRYPT_KEY');
        $busiparams = [
            "sign"=> "123456"
        ];
        $params_array = [
            "sysparams" => $sysparams,
            "busiparams" => $busiparams,
        ];
        $params = json_encode($params_array);
        /*$params = '{
"sysparams":{
		"busiCode": "UIP_IMAGE_CONTRAS",
		"sourceId": "1002",
		"busiSerial":"100220181126164001000001",
		"format": "json",
	"sign":"TSUu7Zkvz92bNv06ajbc0tG1u56bujic2Uwsy2UmguQufaqD+sWsSvXzdEKAfF9O8q1I/OeRuiEX2WAYJKlfsOET8oGnOtCn4Icf68hdPZAMKGk8Q1f7I0BDCAmB6WSd1o3pTU+9L5GAuE/hds075V/crkPO1Z+/KxFWcStRMxEcvIzuTLZEeXtjjujuX4kXrBkF462yZHPq6mSlBJn2+AbIud7w0PieMh3o5jsLvrRY3smmk3gZo9ciR+1ST/C7C1lvDIBKA+IJo0ijMRbH8QNMxCuxkJTYsz0K4SOG8A5gcQJHk3SC1wWKQvsGofOIXzz6/vUDw1ACsHTwCYMNfg=="
	},
"busiparams": {
"entryData":"da4e7ed947a9f38cc517419bd1a9565739306b22451f827c5bef9f0b6d08d34641b0cda2dc8c936edc100ac0790a6e204d449c72427d34b7e7eccaa3adb95e6ae1fe21e5ed5457eba1b873ef081f3ea5c315129f6484de85"
  }
}';*/
        $url = "https://www.ha.10086.cn/uip/open/api";
        var_dump($params);
        $result = $this->curlHttpRequest($url, 'POST', $params);
        var_dump($result);die;
    }

    /**
     * 测试授权信息
     *
     */
    public function test(Request $request){
        $admin_user_info = DB::table('admin_users')->where(['id'=> $request->id])->first();
        $user_info = DB::table('users')->where('account',$admin_user_info->account)->first();
        if($user_info){
            $h5_index = env('APP_URL') . "/h5";
            $basic_url = $h5_index."?first_uid=".$user_info->id;

            $img_info = DB::table("backgroud")->orderBy('id', 'desc')->first();
            $img_background = $img_info? $img_info->value: "";

            // 生成二维码图片
            $qrc = get_qrcodes($basic_url, date("Ymdhis"), $img_background);
            if ( !$qrc ){
                $qrc = '';
            }
        } else {
            $qrc = '';
        }

        $admin_user_data['qr_code'] = $qrc;

        $res = DB::table('admin_users')->where(['id'=> $admin_user_info->id])->update($admin_user_data);
        if ( $res ) {
            return ['code'=> 200, 'msg'=> 'success'];
        }else{
            return ['code'=> 201, 'msg'=> 'failed'];
        }
    }
}
